package com.atguigu.spring6iocxml.bean;

import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestUser {

    Logger logger = LoggerFactory.getLogger(TestUser.class);

    @Test
    public void testUserObje() {
        ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");
        // 根据id获取bean对象
        User user = (User) context.getBean("user");
        logger.info("根据id获取bean对象-user对象：{}", user);
        // 根据类型获取bean对象
        User user2 = context.getBean(User.class);
        logger.info("根据类型获取bean对象-user对象：{}", user2);
        // 根据ID与类型获取bean对象
        User user3 = context.getBean("user", User.class);
        logger.info("根据ID与类型获取bean对象-user对象：{}", user3);
    }

    /**
     * 如果有多个实现类，那么根据类型获取bean对象会报错
     */
    @Test
    public void testBeanObject() {
        ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");
        // 根据类型获取bean对象
        UserDao userDao = context.getBean(UserDao.class);
    }
}
